package com.mybatis.core;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author yangjian
 */
public class DatasourceFactory {

  private static Connection connection;

  /**
   * 获取数据库连接对象
   */
  public static synchronized Connection getConnection() throws ClassNotFoundException, SQLException {
    if (null == connection) {
      Class.forName("com.mysql.cj.jdbc.Driver");
      String url = "jdbc:mysql://localhost:3306/test";
      String user = "root";
      String password = "12345678";
      connection = DriverManager.getConnection(url, user, password);
    }
    return connection;
  }
}
